﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;

namespace MINERP.DAL.CustomerManage
{
    public class PhotoInfoDAL : DALBase
    {
        /// <summary>
        /// 得到产品的其中一张照片路径
        /// </summary>
        /// <param name="orderInfoID"></param>
        /// <returns></returns>
        public static string GetOnePicPathByOrderInfoID(int orderInfoID)
        {
            ObjectQuery<string> list = DataEntites.CreateQuery<string>(string.Format("SELECT VALUE it.picPath FROM PhotoInfo as it WHERE it.orderInfo.OrderProductId = {0}", orderInfoID));

            if (list.Count() > 0)
                return list.First();

            return string.Empty;
        }
        public static string GetOnePicPathByOrderInfoID_bk(int orderInfoID)
        {
            ObjectQuery<string> list = DataEntites.CreateQuery<string>(string.Format("SELECT VALUE it.picPath FROM PhotoInfo_bk as it WHERE it.orderInfo_bk.OrderProductId = {0}", orderInfoID));

            if (list.Count() > 0)
                return list.First();

            return string.Empty;
        }

       /// <summary>
       /// 得到产品的所有照片路径
       /// </summary>
       /// <param name="orderInfoID"></param>
       /// <returns></returns>
        public static List<string> GetAllPathByOrderInfoID(int orderInfoID)
        {
            //ObjectQuery<string> list = DataEntites.CreateQuery<ObjectQuery>(string.Format("SELECT it.picPath,it.PhotoBarCode FROM PhotoInfo as it WHERE it.orderInfo.OrderProductId = {0}", orderInfoID));
            List<photoInfo> list = DataEntites.photoInfo.Where(p => p.orderInfo.OrderProductId == orderInfoID).ToList();
            List<string> listPath = new List<string>();

            foreach (photoInfo photo in list)
            {
                listPath.Add(photo.picPath);
                listPath.Add(photo.PhotoBarCode);
            }

            return listPath;
        }

        /// <summary>
        /// 得到产品的所有照片
        /// </summary>
        /// <param name="orderinfoid"></param>
        /// <returns></returns>
        public static List<photoInfo> GetPhotoByOrderInfoID(int orderinfoid)
        {
            using (newSampleYPDBEntities db = new newSampleYPDBEntities())
            {
                return db.photoInfo.Include("paperType").Include("paperFace").Where(p => p.orderInfo.OrderProductId == orderinfoid).ToList();
            }
            //ObjectQuery<photoInfo> list = DataEntites.photoInfo.Where(string.Format("it.orderInfo.OrderProductId = {0}", orderinfoid)).Include("paperType").Include("paperFace");
            //DataEntites.Refresh(RefreshMode.StoreWins, list);
            //List<photoInfo> collection = new List<photoInfo>();

            //collection.AddRange(list);

            //return collection;
        }
        /// <summary>
        /// 得到产品的所有照片(备份)
        /// </summary>
        /// <param name="orderinfoid"></param>
        /// <returns></returns>
        public static List<photoInfo_BK> GetPhotoByOrderInfoID_bk(int orderinfoid)
        {
            using (newSampleYPDBEntities db=new newSampleYPDBEntities ())
            {
                return db.photoInfo_BK.Include("paperType").Include("paperFace").Where(p => p.orderInfo_BK.OrderProductId == orderinfoid).ToList();
            }
            //ObjectQuery<photoInfo_BK> list = DataEntites.photoInfo_BK.Where(string.Format("it.orderInfo_BK.OrderProductId = {0}", orderinfoid)).Include("paperType").Include("paperFace");
            //DataEntites.Refresh(RefreshMode.StoreWins, list);
            //List<photoInfo_BK> collection = new List<photoInfo_BK>();

            //collection.AddRange(list);

            //return collection;
        }
    }
}
